import Vue from 'vue'
import moment from 'moment'
import 'moment/locale/zh-cn'
moment.locale('zh-cn')

Vue.filter('NumberFormat', function (value) {
  if (!value) {
    return '0'
  }
  const intPartFormat = value.toString().replace(/(\d)(?=(?:\d{3})+$)/g, '$1,') // 将整数部分逢三一断
  return intPartFormat
})

Vue.filter('dayjs', function (dataStr, pattern = 'YYYY-MM-DD HH:mm:ss') {
  return moment(dataStr).format(pattern)
})

Vue.filter('moment', function (dataStr, pattern = 'YYYY-MM-DD HH:mm:ss') {
  return moment(dataStr).format(pattern)
})


//#region  界面上用于是、否、冻结、正常显示的

const statusFlag = {
  disable: {
    status: 'default',
    text: '禁用'
  },
  enable: {
    status: 'success',
    text: '启用'
  }
}

Vue.filter('statusTextFilter', function (data) {
  return data.text ? statusFlag.enable.text : statusFlag.disable.text;
})

Vue.filter('statusTypeFilter', function (data) {
  return data.text ? statusFlag.enable.status : statusFlag.disable.status;
})

const yesNoFlag = {
  /**
   * 后端值为：0
   */
  no: {
    status: 'default',
    text: 'NO'
  },
  /**
   * 后台值为1
   */
  yes: {
    status: 'success',
    text: 'YES'
  }
}

Vue.filter('yesNoTextFilter', function (data) {
  return data ? yesNoFlag.yes.text : yesNoFlag.no.text;
})

Vue.filter('yesNoTypeFilter', function (data) {
  return data ? yesNoFlag.yes.status : yesNoFlag.no.status;
})
//#endregion


//#region 横幅类型
// 横幅类型
export const bannerTypes = [
  { id: 0, name: "文字" },
  { id: 1, name: "图片" },
  { id: 2, name: "视频" },
];
Vue.filter('bannerTypeFilter', function (id) {
  let bannerType = this.bannerTypes.filter((m) => m.id === id)
  return bannerType[0].name
})
//#endregion